package com.zyong.design.pattern.state.case2;

/**
 * @author zyong
 */
public class Activity {
    /**
     * state表示活动当前的状态，是变化
     */
    AbstractState state;
    /**
     * 奖品数量
     */
    int count;

    /**
     * 四个属性，表示四种状态
     */
    AbstractState noRaffleState = new NoRaffleAbstractState(this);
    AbstractState canRaffleState = new CanRaffleAbstractState(this);
    AbstractState distributeState = new DistributeAbstractState(this);
    AbstractState distributeOutState = new DistributeOutAbstractState(this);

    public Activity(int count) {
        this.state = getNoRaffleState();
        this.count = count;
    }

    /**
     * 扣除积分，调用当前状态的deductingPoints
     */
    public void deductingPoints() {
        state.deductingPoints();
    }

    /**
     * 抽奖
     */
    public void raffle() {
        // 如果当前的状态是抽奖成功
        if (state.raffle()) {
            // 领取奖品
            state.distributePrizes();
        }
    }

    public AbstractState getState() {
        return state;
    }

    public void setState(AbstractState state) {
        this.state = state;
    }

    /**
     * 这里请大家注意，每领取一次奖品，count--
     * @return
     */
    public int getCount() {
        int curCount = count;
        count--;
        return curCount;
    }

    public AbstractState getNoRaffleState() {
        return noRaffleState;
    }

    public AbstractState getCanRaffleState() {
        return canRaffleState;
    }

    public AbstractState getDistributeState() {
        return distributeState;
    }

    public AbstractState getDistributeOutState() {
        return distributeOutState;
    }
}
